# -*- coding: iso-8859-2 -*-

import re
import string

from authorshipanalyzer.slot import Filler
from authorshipanalyzer.textutils import Splitter
from authorshipanalyzer.clp import ClpUtils
from authorshipanalyzer.file import ResourceReader
from authorshipanalyzer.file import Path

import os

class WordFeaturesFiller(Filler):
    '''
    Fill slot with word based features
    '''
    
    def __init__(self):
        self.splitter = Splitter()       
    
    def fill(self, slot):
        '''
        Fill a slot
        '''
        slot.wordFrequency = self.splitter.getWordFrequencyDict(slot.message.getText())
        
        functionWords = ResourceReader().readWordList(Path.getResourceDir() + os.sep + "functionWords.txt")
        
        textWordFrequency = self.splitter.getWordFrequencyDict(slot.text)
        for key, val in textWordFrequency.items():
            if key in functionWords:
                continue
            
            if slot.contentWordFrequency.has_key(key):
                slot.contentWordFrequency[key] += val
            else:
                slot.contentWordFrequency[key] = val
        